#include "Buffer.h"
#include <string.h>

Buffer::Buffer(){
	buf = new char[10240];//可以是config
	len = 0;
}
Buffer::~Buffer(){
	if(buf != NULL){
		delete buf ;
		buf = NULL;
		len = 0;
	}
}

void Buffer::pushData(const char *_b, unsigned int _s){
	if( _s > 0 ){
		memcpy(buf, _b, _s);
		len += _s;
	}
}

int Buffer::popData(char *_b, unsigned int _s){
	if( _s > 0 && _b != NULL ){
		if( _s > len ){
			_s = len;
		}
		memcpy(_b, buf, _s);
		len -= _s;
		memmove(buf+_s, buf, len); 
	}
	return _s;
}

int Buffer::lookData(char *_b, unsigned int _s){
	if( _s > 0 && _b != NULL ){
		if( _s > len ){
			_s = len;
		}
		memcpy(_b, buf, _s);
	}
	return _s;
}

unsigned int Buffer::size(){
	return len;
}

